﻿using System;
using System.Data;
using System.Web;
using System.Collections;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Collections.Generic;

namespace LabMS.Web.User
{
    /// <summary>
    /// Summary description for $codebehindclassname$
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    public class CheckUserNameAndPsw : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string psw = context.Request.Params["Password"].ToString();
            string usercode = context.Request.Params["UserCode"].ToString();
            string usertype = context.Request.Params["UserType"].ToString();
            string returnvalue="";
            if (usertype == "mana")
            {
                LabMS.BLL.UserTable userTable = new LabMS.BLL.UserTable();
                List<LabMS.Model.UserTable> userTableModelList = new List<LabMS.Model.UserTable>();

                userTableModelList = userTable.GetModelList("Password='" + psw + "' and PCode='" + usercode + "'");
                if (userTableModelList.Count == 1)
                {
                    returnvalue = "\"" + psw + "\",true";
                }
                else
                {
                    returnvalue = "\"" + psw + "\",false";
                }
            }
            else if (usertype == "student")
            {
                LabMS.BLL.Student userTable = new LabMS.BLL.Student();
                List<LabMS.Model.Student> userTableModelList = new List<LabMS.Model.Student>();

                userTableModelList = userTable.GetModelList("Student_Pass='" + psw + "' and Student_Code='" + usercode + "'");
                if (userTableModelList.Count == 1)
                {
                    returnvalue = "\"" + psw + "\",true";
                }
                else
                {
                    returnvalue = "\"" + psw + "\",false";
                }
            }
            if (usertype == "teacher")
            {
                LabMS.BLL.Teacher userTable = new LabMS.BLL.Teacher();
                List<LabMS.Model.Teacher> userTableModelList = new List<LabMS.Model.Teacher>();

                userTableModelList = userTable.GetModelList("Password='" + psw + "' and Teacher_Code='" + usercode + "'");
                if (userTableModelList.Count == 1)
                {
                    returnvalue = "\"" + psw + "\",true";
                }
                else
                {
                    returnvalue = "\"" + psw + "\",false";
                }
            }
            
            context.Response.Write(returnvalue);
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}
